1. Technical Field
The present invention relates in general to a system and method for lightweight task switching when a shared memory condition is signaled. More particularly, the present invention relates to a system and method for using a handler to detect asynchronous lock line reservation lost events, and switching tasks based upon whether a condition is true or whether a processor acquires a mutex lock.
2. Description of the Related Art
Computer applications typically run multiple threads to perform different tasks that request access to shared data. Common approaches to accessing shared data are 1) using a mutual exclusion (mutex) lock primitive or 2) using a condition wait primitive.
A mutex lock allows multiple threads to “take turns” sharing the same resource, such as accessing a file. Typically, when a program starts, the program creates a mutex object for a given resource by requesting the resource from the system, whereby the system returns a unique name or identifier for the resource. After that, a thread requiring the resource uses the mutex to “lock” the resource from other threads while the thread uses the resource. When the mutex is locked, the system typically queue's threads requesting the resource and then gives control to the threads when the mutex becomes unlocked.
A condition wait primitive allows a thread to identify whether a condition has occurred by accessing cache line data, such as whether a video card has completed a vertical retrace. The condition wait primitive allows a thread to wait until a particular condition is met before proceeding. A challenge found with both mutex lock primitives and condition wait primitives is that system performance decreases when threads wait for data to become available.
As such, task switching is a common approach to increasing system performance when a system invokes multiple threads. Task switching allows a processor to switch from one thread to another thread without losing its “spot” in the first thread. Task switching is different than multitasking because, in multitasking, a processor switches back and forth quickly between threads, giving the appearance that all programs are running simultaneously. In task switching, the processor does not switch back and forth between threads, but executes one thread at a time. A challenge found with task switching, however, is that task switching typically occurs at pre-determined intervals. For example, a processor may check every 10 milliseconds as to whether a particular lock has been acquired for a requesting thread.
What is needed, therefore, is a system and method to efficiently task switch between threads when a thread's requested resource becomes available.